package hibernate;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import bean.MessagePriveBean;


public class MessagePriveRepository extends GenericRepository<MessagePriveBean, Integer> implements Serializable {

	private static final long serialVersionUID = 1L;

	public MessagePriveBean GetById(Integer Id){
		Session s = HelperSessionFactory.getSession();
		Transaction trans = s.beginTransaction();
		Criteria criteria = s.createCriteria(MessagePriveBean.class).add(Restrictions.eq("id_message", Id));
		MessagePriveBean msg = (MessagePriveBean) criteria.uniqueResult();
		trans.commit();
		return msg;
	}

	public List<MessagePriveBean> GetAll(){
		Session s = HelperSessionFactory.getSession();
		Transaction trans = s.beginTransaction();
		Criteria criteria = s.createCriteria(MessagePriveBean.class);
		@SuppressWarnings("unchecked")
		List<MessagePriveBean> lst = (List<MessagePriveBean>) criteria.list();
		trans.commit();
		return lst ;
	}


	public List<MessagePriveBean> GetAllMessagePriveByDestinataire(int id_destinataire){
		Session s = HelperSessionFactory.getSession();
		Transaction trans = s.beginTransaction();
		Criteria criteria = s.createCriteria(MessagePriveBean.class).add(Restrictions.eq("id_eleve_destinataire", id_destinataire)).add(Restrictions.eq("privacy", true));
		@SuppressWarnings("unchecked")
		List<MessagePriveBean> lst = (List<MessagePriveBean>) criteria.list();
		trans.commit();
		return lst ;
	}
}
